﻿function verifyJoinForm()
{
	msg = document.getElementById('flash-msg');
	var pattern=/[~`<>\\\/&\s]/;
	
	var joinform = document.getElementById ('joinform');
	nickname = joinform.nickname.value.replace(/^\s*/,'').replace(/\s*$/,'');
    if (nickname.length <=0)
    {
    	msg.innerHTML ='必须输入昵称!';
		return false;
    }	
	if (pattern.test(nickname))
	{
		msg.innerHTML ='请正确输入昵称,不能包含&amp;,&lt;&gt;&quot;&#39;等字符';
		return false;
	}
	
	pattern=/[~`<>\\\/&]/;
	intro = joinform.intro.value.replace(/^\s*/,'').replace(/\s*$/,'');
    if (intro.length <=0)
    {
    	msg.innerHTML ='必须输入说明!';
		return false;
    }	
	if (pattern.test(intro))
	{
		msg.innerHTML ='请正确输入个人说明,不能包含&amp;,&lt;&gt;&quot;&#39;等字符';
		return false;
	}
	el = document.getElementById('submit');
	if(el!=null)
	{
		el.disabled = true;
	}
	return true;
}

function changeView()
{ 
  var   myForm=document.forms['myForm'];  
  myForm.submit();   
}

function verifyAddForm()
{
    var pattern=/[~`<>\\\/&]/;
    msg = document.getElementById('flash-msg');
    
    var addform = document.getElementById('addform');
    des = addform.description.value.replace(/^\s*/,'').replace(/\s*$/,'');
    if (des.length <=0)
    {
    	msg.innerHTML ='必须输入备注!';
		return false;
    }
    if(pattern.test(des))
    {
        msg.innerHTML ='备注不能包含&amp;,&lt;&gt;&quot;&#39;等字符!';
	    return false; 
    }
    
    var money_pat=/^\d+(\.\d+)?$/;
    
    money = addform.money.value.replace(/^\s*/,'').replace(/\s*$/,'');
    if (money.length <=0)
    {
    	msg.innerHTML ='必须输入金额!';
		return false;
    }
	if (!money_pat.test(money))
	{
	    msg.innerHTML ='金额必须为数字!';
	    return false;
	}

    el = document.getElementById('submit');
    if(el!=null)
    {
        el.disabled = true;
    }
    return true;
}

function onCheckBoxMoseOver(event, key)
{ 
    var el = event.currentTarget;
    if (el == null)
    {
        el = document.getElementById(key);
    }
    el.checked = ! el.checked;

}

function verifyListForm(name)
{  
    var msg = document.getElementById('flash-msg');
    var els = document.getElementsByName(name);
    checkedcount = 0;
    for(i=0 ; i<els.length ; i++)
    {
        if (els[i].checked)
        {
            checkedcount++;
        }
    }
    if (checkedcount<=0)
    {
        msg.innerHTML ='请选择项目!';
        return false;
    }
    return confirm('确定?');   	
} 

function selectAll(name)
{
   var selectall = document.getElementById('selectall');
   var els = document.getElementsByName(name);
   for(i=0 ; i<els.length ; i++)
   {
       els[i].checked = selectall.checked;
   }
}

function verifyCreateForm()
{
	msg = document.getElementById('flash-msg');
	var pattern=/[~`<>\\\/&\s]/;
	
	var createform = document.getElementById('createform');
	GroupName = createform.GroupName.value.replace(/^\s*/,'').replace(/\s*$/,'');
	if (GroupName.length <=0)
	{
	   msg.innerHTML = '请输入名称';
	   return false;
	}
	if (pattern.test(GroupName))
	{
		msg.innerHTML ='请正确输入名称,不能包含&amp;,&lt;&gt;&quot;&#39;等字符';
		return false;
	}
	
	pattern=/[~`<>\\\/&]/;
	Description = createform.Description.value.replace(/^\s*/,'').replace(/\s*$/,'');
	if (Description.length <=0)
	{
	   msg.innerHTML = '请输入说明';
	   return false;
	}
	if (pattern.test(Description))
	{
		msg.innerHTML ='请正确输入说明,不能包含&amp;,&lt;&gt;&quot;&#39;等字符';
		return false;
	}
	el = document.getElementById('submit');
	if(el!=null)
	{
		el.disabled = true;
	}
	return true;
}

function selectdesc(desc)
{
    var addform = document.getElementById('addform');
    var desctextarea = addform.description;
    desctextarea.value = desc;
    showlatest('none');
}

function getAbsolutePos(el) 
{
	var SL = 0, ST = 0;
	var is_div = /^div$/i.test(el.tagName);
	if (is_div && el.scrollLeft)
		SL = el.scrollLeft;
	if (is_div && el.scrollTop)
		ST = el.scrollTop;
	var r = { x: el.offsetLeft - SL, y: el.offsetTop - ST };
	if (el.offsetParent) {
		var tmp = this.getAbsolutePos(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	return r;
}

function showlatest(visible)
{ 
   var latest = document.getElementById('latestdesc');
   var addform = document.getElementById('addform');
   var desc = addform.description;
   var style_latest = latest.style;
   var loc = getAbsolutePos(desc);
   style_latest.left = (loc.x + 5 + desc.offsetWidth)+ "px";
   style_latest.top = loc.y  + "px";
   style_latest.display = visible;
}
